package org.wattdepot.cli.commands;

import org.junit.Test;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * This class tests the list source command of the CommandLineInterface's actual commands.
 * @author David Mau
 */
public class TestCommandListSources {
  
  /**
   * Tests the normal operation of the list sources command.
   */
  @Test
  public void testListSources() {
    // Create a new list sources command object.
    ListSourcesCommand command = new ListSourcesCommand(null);
    // Create a new List to store the args
    List<String> args = new ArrayList<String>();
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the children are listing their parents properly
    assertTrue("Checking AES and IPP", sourceOutput.contains("SIM_AES          SIM_IPP"));
    assertTrue("Checking HONOLULU and the Oahu Grid", sourceOutput
        .contains("SIM_HONOLULU     SIM_OAHU_GRID"));
    assertTrue("Checking HONOLULU #8 and Honolulu", sourceOutput
        .contains("SIM_HONOLULU_8   SIM_HONOLULU"));
    assertTrue("Checking HPOWER and IPP", sourceOutput.contains("SIM_HPOWER       SIM_IPP"));
    assertTrue("Checking IPP's relation to the Oahu Grid", sourceOutput
        .contains("SIM_IPP          SIM_OAHU_GRID"));
    assertTrue("Checking KAHE's relation to the Oahu Grid", sourceOutput
        .contains("SIM_KAHE         SIM_OAHU_GRID"));
    assertTrue("Checking that KAHE #1's parent is KAHE", sourceOutput
        .contains("SIM_KAHE_1       SIM_KAHE"));
    assertTrue("Checking that KALAELOA's parent is IPP", sourceOutput
        .contains("SIM_KALAELOA     SIM_IPP"));
    assertTrue("Checking to see that the Oahu Grid has no parent", sourceOutput
        .contains("SIM_OAHU_GRID            "));
    assertTrue("Checking that WAIAU has the Oahu Grid as a parent", sourceOutput
        .contains("SIM_WAIAU        SIM_OAHU_GRID"));
    assertTrue("Checking that WAIAU #5's parent is WAIAU", sourceOutput
        .contains("SIM_WAIAU_5      SIM_WAIAU"));
    
  }
  
  /**
   * Tests to see if the list sources command can handle excess arguments.
   */
  @Test
  public void testExcessArguments() {
    // Create a new list sources command object.
    ListSourcesCommand command = new ListSourcesCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList("1");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking excess ListSource argument handling", 
        sourceOutput.contains(WattDepotCliCommand.tooManyArguments));
  }
}
